using System;
using System.Text;
using System.Xml;
using System.Configuration;

namespace Geekees.App.HRAssistant.Core.Configuration
{
	public class DaoSettingHandler : IConfigurationSectionHandler
	{
		private DaoSettingCollection dsc = new DaoSettingCollection();

		public Object Create( object parent, object context, XmlNode node )
		{
			LoadValues( node );
			return dsc;
		}

		internal void LoadValues( XmlNode node )
		{
			XmlAttributeCollection attributeCollection = node.Attributes;
			foreach( XmlNode c in node.ChildNodes )
			{
				switch( c.Name )
				{
					case "DaoSettings":
						LoadDataSettings( c );
						break;
				}
			}
		}
		private void LoadDataSettings( XmlNode node )
		{
			foreach( XmlNode dsn in node.ChildNodes )
			{
				switch( dsn.Name )
				{
					case "DaoSetting":
						DaoSetting ds = new DaoSetting( dsn.SelectSingleNode( "AssemblyName" ).InnerText, dsn.SelectSingleNode( "AssemblyTypeName" ).InnerText, dsn.SelectSingleNode( "ConnectionStr" ).InnerText, Convert.ToBoolean( dsn.Attributes["IsActive"].Value ) );
						dsc.Add( ds );
						break;
					case "Clear":
						dsc.Clear();
						break;
				}
			}
		}
	}
}
